//
//  Mediator+BKOrder.m
//  bestkeep
//
//  Created by 马乾征 on 16/11/4.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "Mediator+BKOrder.h"
#import "BKOrderAction.h"

NSString *const BKOrderTarget = @"BKOrderAction";
NSString *const BKOrderActionOrderViewController = @"BKOrder_orderViewControllerWithParameter:";
NSString *const BKOrderActionOrderPaymentViewController = @"BKOrder_paymentViewControllerWithParameter:";
NSString *const BKOrderActionOrderDeliveryDateViewController = @"BKOrder_deliveryDateViewControllerWithParameter:";
NSString *const BKOrderActionWXHandleUrl = @"BKOrder_WXHandleOpenUrl:";
NSString *const BKOrderActionAliHandleUrl = @"BKOrder_AliHandleOpenUrl:";
NSString *const BKOrderActionAliHandleDidFinish = @"BKOrder_AliHandleDidFinishLaunching:";
@implementation Mediator (BKOrder)

/**
    提交订单
 */
- (UIViewController *)BKOrder_orderViewControllerWithParameter:(NSArray <NSDictionary *> *)parameter
{
    UIViewController *orderVC = [self generateViewControllerWithParam:parameter Action:BKOrderActionOrderViewController error:@"提交订单_请设置订单参数"];
    return orderVC;
}

#pragma mark  internal action
- (UIViewController *)generateViewControllerWithParam:(id)parameter Action:(NSString *)action error:(NSString *)error
{
    MediatorOptions *options = [MediatorOptions optionsWithTargetName:BKOrderTarget actionName:action];
    if (parameter == nil)
    {
        NSLog(@"ERROR : %@",error);
    }
    
    options.parameters = @{@"parameter" : parameter};
    UIViewController *viewController = [self performWithOptions:options];
    
    if (!viewController) {
        return [[UIViewController alloc] init];
    }
    return viewController;
}


@end

@implementation Mediator (BKODDeliveryDate)

/**
    选择发货日期
 */
- (UIViewController *)BKOrder_deliveryDateViewControllerWithParameter:(NSDictionary <NSString *, id> *)parameter
{
    UIViewController *deliverDateVC = [self generateViewControllerWithParam:parameter Action:BKOrderActionOrderDeliveryDateViewController error:@"选择发货日期_请设置相关参数"];
    return deliverDateVC;
}

@end

@implementation Mediator (BKODHandleOpenUrl)


/**
    微信结果
 */
- (void)BKOrder_WXHandleOpenUrl:(NSURL *)url
{
    MediatorOptions *options = [MediatorOptions optionsWithTargetName:BKOrderTarget actionName:BKOrderActionWXHandleUrl];
    options.parameters = @{@"parameter" : url};
    [self performWithOptions:options];
}

/**
    支付宝结果
 */
- (void)BKOrder_AliHandleOpenUrl:(NSURL *)url
{
    MediatorOptions *options = [MediatorOptions optionsWithTargetName:BKOrderTarget actionName:BKOrderActionAliHandleUrl];
    options.parameters = @{@"parameter" : url};
    [self performWithOptions:options];
}

//- (void)BKOrder_AliHandleDidFinishLaunching:(NSDictionary *)parameter
//{
//    MediatorOptions *options = [MediatorOptions optionsWithTargetName:BKOrderTarget actionName:BKOrderActionAliHandleDidFinish];
//    options.parameters = @{@"parameter" : parameter ? parameter : @{}};
//    [self performWithOptions:options];
//}
@end





@implementation Mediator (BKODPayment)

/**
    订单支付
 */

- (UIViewController *)BKOrder_paymentViewControllerWithParameter:(NSDictionary *)parameter
{
    UIViewController *payVC = [self generateViewControllerWithParam:parameter Action:BKOrderActionOrderPaymentViewController error:@"订单支付_请设置订单支付所需参数"];
    return payVC;
}
@end

